from django.db import models


# Create your models here.

class examuser(models.Model):
    name = models.CharField(max_length=20, unique=True, verbose_name="用户名")
    password = models.CharField(max_length=20, verbose_name="密码")

    class Meta:
        db_table = "examuser"

    def __str__(self):
        return self.name


class booktype(models.Model):
    name = models.CharField(max_length=20, unique=True, verbose_name="类型名称")

    class Meta:
        db_table = "booktype"

    def __str__(self):
        return self.name


class author(models.Model):
    name = models.CharField(max_length=20, unique=True, verbose_name="作者")

    class Meta:
        db_table = "author"

    def __str__(self):
        return self.name


class book(models.Model):
    title = models.CharField(max_length=40, unique=True, verbose_name="书名")
    status = models.BooleanField(default=True, verbose_name="状态")
    author = models.ForeignKey(author, on_delete=models.CASCADE, related_name='bookauthor')
    booktype = models.ForeignKey(booktype, on_delete=models.CASCADE, related_name='mybookauthor')

    class Meta:
        db_table = "book"

    def __str__(self):
        return self.title
